cmake_minimum_required(VERSION 3.7.1)
project(cpp_streamer)

#set(CMAKE_CXX_FLAGS  "${CMAKE_CXX_FLAGS} -std=c++11 -g -Wno-deprecated -Wno-deprecated-declarations -Wno-reorder -Wall -fexceptions -frtti -D__STDC_FORMAT_MACROS -fPIC")
set(CMAKE_CXX_FLAGS  "${CMAKE_CXX_FLAGS} -std=c++20 -g -Wno-deprecated -Wno-deprecated-declarations -Wall -fexceptions -frtti -D__STDC_FORMAT_MACROS -fPIC")


set(CMAKE_OUTPUT_BASE ${CMAKE_BINARY_DIR}/output)
set(BUILD_OUTPUT_BASE ${CMAKE_BINARY_DIR}/output)
set(PREFIX_DIR "${BUILD_OUTPUT_BASE}")
set(INSTALL_RPATH "${PREFIX_DIR}/lib")

# set output static libary
SET(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/output/lib)

# set pkgconfig path
set(CMAKE_PREFIX_PATH "${CMAKE_BINARY_DIR}/output/lib/pkgconfig")

if (CMAKE_SYSTEM_NAME STREQUAL "Darwin")
if (CMAKE_SYSTEM_PROCESSOR STREQUAL "arm64")
message("-----This is MacOs arm64")
else()
message("-----This is MacOs Intel")
endif()
else()
message("-----This is system ${CMAKE_SYSTEM_NAME}")
endif()
message("-----------------------------------------------")
message("-----------------------------------------------")
message("-----------------------------------------------")

# set include path
include_directories(${CMAKE_BINARY_DIR}/output/include
                    ${CMAKE_BINARY_DIR}/output/include/openssl
                    src
                    src/net
                    src/net/tcp
                    src/net/rtmp
                    src/format
                    src/format/flv
                    src/format/amf
                    src/utils
                    src/utils/av
                    /usr/local/include)

# set lib path
IF (APPLE)
link_directories(${CMAKE_BINARY_DIR}/output/lib /usr/local/lib)
ELSEIF (UNIX)
link_directories(${CMAKE_BINARY_DIR}/output/lib /usr/local/lib64 /usr/local/lib)
ENDIF ()

add_subdirectory(3rdparty)

################################################################
# example: live server
add_executable(live_server
            ${PROJECT_SOURCE_DIR}/src/format/amf/amf0.hpp
            ${PROJECT_SOURCE_DIR}/src/format/flv/flv_pub.hpp
            ${PROJECT_SOURCE_DIR}/src/format/flv/flv_pub.cpp
            ${PROJECT_SOURCE_DIR}/src/format/h264_h265_header.hpp
            ${PROJECT_SOURCE_DIR}/src/format/h264_h265_header.cpp
            ${PROJECT_SOURCE_DIR}/src/format/audio_header.hpp
            ${PROJECT_SOURCE_DIR}/src/format/audio_header.cpp
            ${PROJECT_SOURCE_DIR}/src/format/opus_header.hpp
            ${PROJECT_SOURCE_DIR}/src/format/opus_header.cpp
            ${PROJECT_SOURCE_DIR}/src/net/tcp/ssl_client.hpp
            ${PROJECT_SOURCE_DIR}/src/net/tcp/ssl_pub.hpp
            ${PROJECT_SOURCE_DIR}/src/net/tcp/ssl_server.hpp
            ${PROJECT_SOURCE_DIR}/src/net/tcp/tcp_client.hpp
            ${PROJECT_SOURCE_DIR}/src/net/tcp/tcp_pub.hpp
            ${PROJECT_SOURCE_DIR}/src/net/tcp/tcp_server.hpp
            ${PROJECT_SOURCE_DIR}/src/net/tcp/tcp_session.hpp
            ${PROJECT_SOURCE_DIR}/src/net/http/http_common.hpp
            ${PROJECT_SOURCE_DIR}/src/net/http/http_server.hpp
            ${PROJECT_SOURCE_DIR}/src/net/http/http_server.cpp
            ${PROJECT_SOURCE_DIR}/src/net/http/http_session.hpp
            ${PROJECT_SOURCE_DIR}/src/net/http/http_session.cpp
            ${PROJECT_SOURCE_DIR}/src/net/rtmp/chunk_stream.hpp
            ${PROJECT_SOURCE_DIR}/src/net/rtmp/chunk_stream.cpp
            ${PROJECT_SOURCE_DIR}/src/net/rtmp/rtmp_control_handler.hpp
            ${PROJECT_SOURCE_DIR}/src/net/rtmp/rtmp_control_handler.cpp
            ${PROJECT_SOURCE_DIR}/src/net/rtmp/rtmp_handshake.hpp
            ${PROJECT_SOURCE_DIR}/src/net/rtmp/rtmp_handshake.cpp
            ${PROJECT_SOURCE_DIR}/src/net/rtmp/rtmp_pub.hpp
            ${PROJECT_SOURCE_DIR}/src/net/rtmp/rtmp_request.hpp
            ${PROJECT_SOURCE_DIR}/src/net/rtmp/rtmp_server.hpp
            ${PROJECT_SOURCE_DIR}/src/net/rtmp/rtmp_server.cpp
            ${PROJECT_SOURCE_DIR}/src/net/rtmp/rtmp_session_base.hpp
            ${PROJECT_SOURCE_DIR}/src/net/rtmp/rtmp_session_base.cpp
            ${PROJECT_SOURCE_DIR}/src/net/rtmp/rtmp_session.hpp
            ${PROJECT_SOURCE_DIR}/src/net/rtmp/rtmp_session.cpp
            ${PROJECT_SOURCE_DIR}/src/net/rtmp/rtmp_writer.hpp
            ${PROJECT_SOURCE_DIR}/src/net/rtmp/rtmp_writer.cpp
            ${PROJECT_SOURCE_DIR}/src/net/hls/hls_writer.hpp
            ${PROJECT_SOURCE_DIR}/src/net/httpflv/httpflv_server.hpp
            ${PROJECT_SOURCE_DIR}/src/net/httpflv/httpflv_server.cpp
            ${PROJECT_SOURCE_DIR}/src/net/httpflv/httpflv_writer.hpp
            ${PROJECT_SOURCE_DIR}/src/net/httpflv/httpflv_writer.cpp
            ${PROJECT_SOURCE_DIR}/src/utils/av/av.hpp
            ${PROJECT_SOURCE_DIR}/src/utils/av/gop_cache.hpp
            ${PROJECT_SOURCE_DIR}/src/utils/av/gop_cache.cpp
            ${PROJECT_SOURCE_DIR}/src/utils/av/media_packet.hpp
            ${PROJECT_SOURCE_DIR}/src/utils/av/media_statics.hpp
            ${PROJECT_SOURCE_DIR}/src/utils/av/media_stream_manager.hpp
            ${PROJECT_SOURCE_DIR}/src/utils/av/media_stream_manager.cpp
            ${PROJECT_SOURCE_DIR}/src/utils/base64.hpp
            ${PROJECT_SOURCE_DIR}/src/utils/base64.cpp
            ${PROJECT_SOURCE_DIR}/src/utils/byte_crypto.hpp
            ${PROJECT_SOURCE_DIR}/src/utils/byte_crypto.cpp
            ${PROJECT_SOURCE_DIR}/src/utils/byte_stream.hpp
            ${PROJECT_SOURCE_DIR}/src/utils/crc.hpp
            ${PROJECT_SOURCE_DIR}/src/utils/crc.cpp
            ${PROJECT_SOURCE_DIR}/src/utils/data_buffer.hpp
            ${PROJECT_SOURCE_DIR}/src/utils/io_interface.hpp
            ${PROJECT_SOURCE_DIR}/src/utils/ipaddress.hpp
            ${PROJECT_SOURCE_DIR}/src/utils/json.hpp
            ${PROJECT_SOURCE_DIR}/src/utils/logger.hpp
            ${PROJECT_SOURCE_DIR}/src/utils/stream_statics.hpp
            ${PROJECT_SOURCE_DIR}/src/utils/stringex.hpp
            ${PROJECT_SOURCE_DIR}/src/utils/timeex.hpp
            ${PROJECT_SOURCE_DIR}/src/utils/timeex.cpp
            ${PROJECT_SOURCE_DIR}/src/utils/timer.hpp
            ${PROJECT_SOURCE_DIR}/src/utils/uuid.hpp
            ${PROJECT_SOURCE_DIR}/src/live_server_instance.cpp

            )
add_dependencies(live_server openssl uv)
IF (APPLE)
target_link_libraries(live_server dl z m ssl crypto uv)
ELSEIF (UNIX)
target_link_libraries(live_server rt dl z m pthread ssl crypto uv)
ENDIF ()